<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/common/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head>
<title>${appname}-<c:if test="${!empty sessionScope._local_node_session}">${sessionScope._local_node_session.nodeName}-</c:if>${si:ctname("NET_TYPE",sessionScope._netType)}</title>
<%@ include file="/WEB-INF/view/common/css_js_ace.jsp"%>
<script type="text/javascript">

function search(form) {
	$(form).appendPagerParaStr();
	return true;
}
 
 
$(function(){
	$('.tipMe').tooltip({'placement':'top'});
	 if('${param.adapterType}'=='1'){
		 $('#adapterType_true').removeClass("active");
		 $('#adapterType_false').addClass("active");
	 }else{
		 $('#adapterType_true').addClass("active");
		 $('#adapterType_false').removeClass("active");
	 }
})

function adapterInfoList(val){
	 $('#adapterType').val(val);
 	if(val=='1'){
		$('#adapterType_true').removeClass("active");
		$('#adapterType_false').addClass("active");
 	}else{
 		$('#adapterType_true').addClass("active");
 	   	$('#adapterType_false').removeClass("active");
 	}
 	$('#searchForm').submit();
}
 
 
 function getExchAdapter(adapterCode){
	 $.ajax({
			type : "POST",
			dataType : "html",
			cache : false,
			url : _ctx + "/registry/adapter_info_exch.do",
			data : {
				adapterCode : adapterCode
			},
			success : function(data) {
				 $('#data').html( data ); 
				   $('#myModal').modal('show');
			},
			error : function() {
				ui.msg('信息加载错误', 0);
			}
		});
 }

function lockedById(id) {
	ui.confirm('确认禁用该适配器?', function() {
		$.ajax({
			type : "POST",
			dataType : "json",
			cache : false,
			url : _ctx + "/registry/adapter_info_locked.do",
			data : {
				id : id
			},
			success : function(resp) {
				if (resp.status == '1') {
					ui.msg(resp.msg, 1);
					ui.go(_ctx + '/registry/adapter_info_list.do');
				} else {
					ui.msg(resp.msg, 0);
				}
			},
			error : function() {
				ui.msg('信息加载错误', 0);
			}
		});
	});
}



function unBind(id) {
	ui.confirm('确认解绑地址?', function() {
		$.ajax({
			type : "POST",
			dataType : "json",
			cache : false,
			url : _ctx + "/registry/adapter_info_unBind.do",
			data : {
				id : id
			},
			success : function(resp) {
				if (resp.status == '1') {
					ui.msg(resp.msg, 1);
					ui.go(_ctx + '/registry/adapter_info_list.do');
				} else {
					ui.msg(resp.msg, 0);
				}
			},
			error : function() {
				ui.msg('信息加载错误', 0);
			}
		});
	});
}


function unLockedById(id) {
	ui.confirm('确认启用该适配器?', function() {
		$.ajax({
			type : "POST",
			dataType : "json",
			cache : false,
			url : _ctx + "/registry/adapter_info_unlocked.do",
			data : {
				id : id
			},
			success : function(resp) {
				if (resp.status == '1') {
					ui.msg(resp.msg, 1);
					ui.go(_ctx + '/registry/adapter_info_list.do');
				} else {
					ui.msg(resp.msg, 0);
				}
			},
			error : function() {
				ui.msg('信息加载错误', 0);
			}
		});
	});
}
/**
 * 验证服务是否有效
 */
function validateWSDL(wsdlUrl){
	if(wsdlUrl == null || wsdlUrl == ''){
		alert('请填写正确的服务地址！');
		return;
	}else{
		$.ajax({
			   type: "POST",
			   url: _ctx + "/registry/AdaisWsdlAvailable.do",
			   async: true,
			   cache: false,
			   data: {serviceUrl : wsdlUrl},
			   beforeSend: function(){
				  // $("#wsdlValidationBtn").val("正在校验...").attr("disabled","disabled");
		       },
			   success: function(data){
				   if(data.status == 1){
					   alert('校验成功！');
				   }else{
					   alert('校验失败！');
				   }
				//   $("#wsdlValidationBtn").val("校验服务有效性").attr("disabled",null);
			   },
			   error:function(){
				   alert('系统异常,操作失败！');
				 //  $("#wsdlValidationBtn").val("校验服务有效性").attr("disabled",null);
			   }
		});		
	}
}
</script>
</head>
<body>
	<%@ include file="/WEB-INF/view/common/topbar.jsp"%>
	<div class="main-container" id="main-container">
		<div class="main-container-inner">
			<%@ include file="/WEB-INF/view/common/sidebar.jsp"%>
			<div class="main-content">
				<div class="breadcrumbs" id="breadcrumbs">
					<ul class="breadcrumb">
						<li><i class="icon-home home-icon"></i> <a href="#">首页</a></li>
						<li><a href="#">注册管理</a></li>
						<li><a href="#">适配器管理</a></li>
						<li><a href="#">适配器绑定</a></li>
						<li class="active">列表</li>
					</ul>
				</div>
				<div class="page-content">
					<div class="row">
						<div class="col-xs-12"> 
						
						
						<div class="widget-box">
				  				<div class="widget-header header-color-white">
									<div class="widget-toolbar no-border">
										<a href="#" data-action="collapse">
											<i class="icon-chevron-up"></i>
										</a>
									</div>
								</div>
								
					  			<div class="widget-body">
									<div class="widget-main">
					  					<form  id="searchForm"  class="form-search"  action="${ctx}/registry/adapter_info_list.do" method="post" onsubmit="return search(this)">
						 					<input type="hidden" name="adapterType"  id="adapterType" value="${param.adapterType}"/>
						 					<div class="row">
											    <div class="col-xs-4">
														<div class="input-group"> 
														   <span class="input-group-addon">适配器名称：</span> 
															<input type="text" class="form-control"  name="adapterName" id="adapterName" value="${param.adapterName}"/>
														</div>
													  </div>
											   <div class="col-xs-4">
				                                    <div class="input-group">
														<span class="input-group-btn">
															<button type="submit" class="btn btn-purple btn-sm">
																<i class="icon-search icon-on-right bigger-110"></i>
																搜索
															</button>&nbsp;&nbsp;
															
															<a href="${ctx}/registry/adapter_info_list.do?adapterType=${param.adapterType}"
	                                                           class="btn btn-purple btn-sm">
	                                                            <i class="icon-refresh icon-on-right bigger-110"></i>
	                                                                                                                                                                                     清空
	                                                        </a>
														</span>
				                                    </div>
												</div>
						 			 		</div>
										</form>
									</div>
							</div>
						</div>
						

							<div class="hr hr12 hr-dotted"></div>

							 <ul class="nav nav-tabs " id="myTab">
								<li id="adapterType_true"><a href="javascript:void(0);"
									class="navbar-link" onclick="adapterInfoList('0');">全局适配器</a>
								</li>
								<li id="adapterType_false"><a href="javascript:void(0);"
									class="navbar-link" onclick="adapterInfoList('1');">局部适配器</a>
								</li>
							</ul>
 
							<div class="table-responsive">
								<table class="table table-striped table-bordered table-hover">
									<thead>
										<tr>
											<th class="center">序号</th>
											<th>适配器编码</th>
											<th>适配器类型</th>
											<th>适配器名称</th>
											<th>本节点绑定地址</th>
											<th>本节点授权码</th>
											<th>交换节点绑定状态 </th>
											<th>绑定时间</th>
											<c:if test="${islocal eq 1 }"><c:if test="${sessionScope._user_session.slAuthFlag ne 4 }"><th>操作</th></c:if></c:if>
										</tr>
									</thead>
									<tbody>
										<c:forEach var="vo" items="${_data}" varStatus="sta">
											<tr>
												<td class="center">${sta.count}</td>
												<td>${vo.adapterCode}</td>
												<td>${si:adaptorType(vo.adapterCode) }</td>
												<td><span class="tipMe" title="${vo.adapterName}">${si:lmitStrPx(vo.adapterName,80)}</span></td>
												<td><span class="tipMe" title="${vo.wsdlUrl}">
												  <c:if test="${vo.wsdlUrl!=null }">
												    ${si:lmitStrPx(vo.wsdlUrl,80)}
												  </c:if>
												    <c:if test="${vo.wsdlUrl==null }">
												<span class="label label-danger arrowed">未绑定</span>   
												  </c:if>
												</span></td>
												<td>${vo.authCode}</td>
												<td>
												<c:if test="${si:adaptorNum(vo.adapterCode) =='0'}">
												   已有${si:adaptorNum(vo.adapterCode) }个节点绑定
												</c:if>
												<c:if test="${si:adaptorNum(vo.adapterCode) !='0'}">
												<button title="点击查看" type='button' class='btn btn-xs btn-info tipMe' onclick='getExchAdapter("${vo.adapterCode}")' >已有${si:adaptorNum(vo.adapterCode) }个节点绑定</button>
												</c:if>
												</td>
												<td>${si:fmtDate(vo.mtime)}</td>
												<c:if test="${islocal eq 1 }">
													<c:if test="${sessionScope._user_session.slAuthFlag ne 4 }">
														<td>
															<div class="visible-md visible-lg hidden-sm hidden-xs action-buttons"  >
																<a class="green tipMe" href="${ctx}/registry/adapter_info_update/${vo.id}.do" title="绑定地址"> <i class="fa fa-link"></i> </a>
		                  										<a class="blue tipMe" href="javascript:void(0);"  onclick="validateWSDL('${vo.wsdlUrl}')"title="验证接口地址(http)"> <i class="icon-bolt bigger-130"></i> </a>
																<c:if test="${vo.wsdlUrl!=null }">
																  <a class="red tipMe" href="javascript:void(0);" onclick="unBind('${vo.id}')" title="解绑地址"> <i class="fa fa-chain-broken"></i> </a>
																</c:if>
																<%-- <c:choose>
																	<c:when test="${'1'==vo.status}">
																		<a class="green tipMe" href="javascript:void(0);"  title="启用" onclick="unLockedById('${vo.id}')"> 
																			<i class="icon-unlock bigger-130"></i> 
																		</a>
																	</c:when>
																	<c:otherwise>
																		<a class="red tipMe" href="javascript:void(0);"  title="禁用" onclick="lockedById('${vo.id}')"> 
																			<i class="icon-lock bigger-130"></i> 
																		</a>
																	</c:otherwise>
																</c:choose> --%>
															</div>
														</td>
													</c:if>
												</c:if>
											</tr>
										</c:forEach>
									</tbody>
								</table>
								<jsp:include page="/WEB-INF/view/common/pg.jsp">
									<jsp:param value="${ctx }/registry/adapter_info_list.do"
										name="url" />
									<jsp:param value="${_total}" name="total" />
									<jsp:param value="${_urlpara}" name="urlpara" />
								</jsp:include>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	
	
		<div id="myModal" class="modal fade" role="dialog"  tabindex="-1" aria-labelledby="查看" aria-hidden="false">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
		      </div>
				<div   id="data">
	  			</div>
				<div class="modal-footer wizard-actions">
					<button class="btn btn-danger btn-sm pull-left" data-dismiss="modal">
						<i class="icon-remove"></i>
						关闭
					</button>
				</div>
			</div>
		</div>
	</div>
</body>
</html>
